//
// Description: 1018. 最低通行费
// Created by Loading on 2022/11/19.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 110;

// dp[i][j] 表示到 (i,j) 位置时，最低通行费
int dp[N][N];

int main() {
    int n;
    cin >> n;
    int a[n][n];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    memset(dp, 0, sizeof dp);

    // 初始化首行首列
    dp[0][0] = a[0][0];
    for (int i = 1; i < n; ++i) {
        dp[i][0] += dp[i - 1][0] + a[i][0];
        dp[0][i] += dp[0][i - 1] + a[0][i];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            // 由左边和上边最小值进行状态转移
            dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
        }
    }

    cout << dp[n - 1][n - 1] << endl;

    return 0;
}